Auto-refreshing ViewPart by using Job [message #820980] |
Wed, 14 March 2012 16:23  |
Eclipse User |
|
|
|
Hello,
I have an issue updating a view. It's just a label that I am hoping to present the current time.
public class TestView extends ViewPart {
private Label label;
private String jobId;
private Display display;
public TestView() {
System.out.println("TestView.TestView()");
}
@Override
public void createPartControl(Composite parent) {
this.setContentDescription("This is just a test.");
GridLayoutFactory.fillDefaults().applyTo(parent);
label = new Label(parent, SWT.BOLD | SWT.BORDER);
jobId = UUID.randomUUID().toString();
System.out.println("Job ID: " + jobId);
display = parent.getDisplay();
Job job = new Job(jobId) {
protected IStatus run(IProgressMonitor monitor) {
// Assume this getTime() method takes a long time
final String newString = GregorianCalendar.getInstance()
.getTime().toString();
System.out.println("new Time: " + newString);
display.asyncExec(new Runnable() {
public void run() {
// Updating UI has to happen in a thread that is called
// by display.asyncExec.
updateLabel(newString);
}
});
return Status.OK_STATUS;
}
};
job.schedule();
}
@Override
public void setFocus() {
System.out.println("TestView.setFocus()");
label.setFocus();
}
private void updateLabel(String newString) {
System.out.println("TestView.updateLabel()");
if (!label.isDisposed()) {
label.setText(newString);
}
}
}
The current time stamp will show up fine initially, but it will never get updated anymore. How do I
1) Update this label with the current time continuously? I know I can use UICallBack but I think the Job should handle this for me automagically.
2) Update this label when user gets to the page (pull model instead of push).
Thank you,
Ronald
|
|
|
|
|
|
Re: Auto-refreshing ViewPart by using Job [message #821680 is a reply to message #820980] |
Thu, 15 March 2012 13:21   |
Eclipse User |
|
|
|
Hi Ronald,
your code looks good. The only thing missing is a loop in your job. Currently you only update the label once :).
See attached file.
Best regards,
Elias.
begin 644 TestView.java
M<&%C:V%G92!H96QL;SL*"FEM<&]R="!J879A+G5T:6PN1W)E9V]R:6%N0V%L
M96YD87(["FEM<&]R="!J879A+G5T:6PN555)1#L*"FEM<&]R="!O<F<N96-L
M:7!S92YC;W)E+G)U;G1I;64N25!R;V=R97-S36]N:71O<CL*:6UP;W)T(&]R
M9RYE8VQI<'-E+F-O<F4N<G5N=&E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-T<FEN9RD["@D)?0H)?0I]
`
end
--
Elias Volanakis | http://eclipsesource.com
elias (AT) eclipsesource.com | @evolanakis
|
|
|
Re: Auto-refreshing ViewPart by using Job [message #821758 is a reply to message #821047] |
Thu, 15 March 2012 15:42  |
Eclipse User |
|
|
|
Hi Ronald,
the part listener gets call for EVERY view, i.e. not only your particular view.
However, you can use the 'part' parameter to figure out if the notification is relevant for you, i.e.:
@Override
public void partActivated(IWorkbenchPart part) {
if (part == this) {
System.out.println("TestView.partActivated() " + part);
// ...
}
}
@Override
public void partDeactivated(IWorkbenchPart part) {
if (part == this) {
System.out.println("TestView.partDeactivated() " + part);
// ...
}
}
Hope this helps,
Elias.
|
|
|
Re: Auto-refreshing ViewPart by using Job [message #821761 is a reply to message #821047] |
Thu, 15 March 2012 15:42  |
Eclipse User |
|
|
|
Hi Ronald,
the part listener gets call for EVERY view, i.e. not only your particular view.
However, you can use the 'part' parameter to figure out if the notification is relevant for you, i.e.:
@Override
public void partActivated(IWorkbenchPart part) {
if (part == this) {
System.out.println("TestView.partActivated() " + part);
// ...
}
}
@Override
public void partDeactivated(IWorkbenchPart part) {
if (part == this) {
System.out.println("TestView.partDeactivated() " + part);
// ...
}
}
Hope this helps,
Elias.
--
Elias Volanakis | http://eclipsesource.com
elias (AT) eclipsesource.com | @evolanakis
|
|
|
Powered by
FUDForum. Page generated in 0.05100 seconds